//
// Created by Shao Wenhan on 2021/4/12.
//

#include "RandomNumber.h"


void
RandomNumber::nonDuplicatedRandomNumbers(int lowerBound, int upperBound, int numOfRandomNum, vector<int> &numbers)
{
    int i = 0;
    while(i < numOfRandomNum)
    {
        auto randomNum = getRandomNumber(lowerBound, upperBound);
        if(find(numbers.begin(), numbers.begin()+i+1, randomNum) == numbers.begin()+i+1)
            numbers[i++] = randomNum;
    }
}

bool RandomNumber::isCurEleChosen(int appearNum, int totalNum)
{
    if(totalNum < 1 or appearNum > totalNum)
        exit(EXIT_FAILURE);

    auto randomNumber = getRandomNumber(0.0, 1.0);
    return randomNumber < 1.0 * appearNum / totalNum;
}
